package com.treasure.hunt.popup

import android.content.Context
import android.view.View
import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import com.treasure.hunt.R
import kotlinx.android.synthetic.main.popup_dialog_share.view.*
import razerdp.basepopup.BasePopupWindow

class DialogSharePopup(
    context: Context,
    val onConfirm: (view: View) -> Unit
) : BasePopupWindow(context) {

    init {
        setBlurBackgroundEnable(true)
    }

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_dialog_share)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)

        contentView.tvDialogShareWX.setOnClickListener {
            onConfirm(it)
            dismiss()
        }
        contentView.tvDialogShareQQ.setOnClickListener {
            onConfirm(it)
            dismiss()
        }
    }

    override fun onCreateShowAnimation(width: Int, height: Int): Animation {
        return TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 1f,
            Animation.RELATIVE_TO_PARENT, 0f
        ).apply { duration = 400L }
    }

    override fun onCreateDismissAnimation(): Animation {
        return TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 1f
        ).apply { duration = 400L }
    }
}